package com.itheima.demo;

import com.itheima.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class MybatisDemo1 {
    public static void main(String[] args) throws IOException {
        //1.读取核心配置文件
        InputStream is = Resources.getResourceAsStream("sqlMapper.xml");

        //2.构建SqlSessionFactory工厂对象(构建者模式)
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        
        //3.获取SqlSession对象
        SqlSession session = factory.openSession();

        //4.执行
        //selectList() 执行statement对象查询所有
        //namespace+"."+statement对象的id
        List<User> list = session.selectList("one.findAll");
        for (User user : list) {
            System.out.println(user);
        }

        //5.释放资源
        session.close();
    }
}
